﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class HealthInfoView : MonoBehaviour 
{

    public static HealthInfoView _instance;

    public Text PlayerName;
    public Text EnemyName;
    public Slider PlayerHealth;
    public Slider EnemyHealth;
    public Text PlayerHealthText;
    public Text EnemyHealthText;
    public Text PlayerCombo;
    public Text EnemyCombo;

    void Awake()
    {
        _instance = this;
        PlayerCombo.gameObject.SetActive(false);
        EnemyCombo.gameObject.SetActive(false);
    }

    void Start()
    {
        Invoke("UpdateHealth", 1.5f);
    }

    public void UpdateHealth()
    {
        if (TeamManager._instance.CurrenPlayerHealth > TeamManager._instance.MaxPlayerHealth)
            TeamManager._instance.CurrenPlayerHealth = TeamManager._instance.MaxPlayerHealth;

        if (TeamManager._instance.CurrenEnemyHealth > TeamManager._instance.MaxEnemyHealth)
            TeamManager._instance.CurrenEnemyHealth = TeamManager._instance.MaxEnemyHealth;

        PlayerHealth.value = (float)TeamManager._instance.CurrenPlayerHealth / TeamManager._instance.MaxPlayerHealth;
        EnemyHealth.value = (float)TeamManager._instance.CurrenEnemyHealth / TeamManager._instance.MaxEnemyHealth;
        PlayerHealthText.text = TeamManager._instance.CurrenPlayerHealth + " / " + TeamManager._instance.MaxPlayerHealth;
        EnemyHealthText.text = TeamManager._instance.CurrenEnemyHealth + " / " + TeamManager._instance.MaxEnemyHealth;

        if (PlayerAttack._instance.Combo != 0)
        {
            PlayerCombo.gameObject.SetActive(true);
            PlayerCombo.color = Color.green;
            PlayerCombo.text = PlayerAttack._instance.Combo.ToString() + " 连击  " + PlayerAttack._instance.ComboHealth.ToString() + " 伤害";
        }

        else
            PlayerCombo.gameObject.SetActive(false);

        if (EnemyAI._instance.Combo != 0)
        {
            EnemyCombo.gameObject.SetActive(true);
            PlayerCombo.color = Color.red;
            EnemyCombo.text = EnemyAI._instance.Combo.ToString() + " 连击  " + EnemyAI._instance.ComboHealth.ToString() + " 伤害";
        }
        else
            EnemyCombo.gameObject.SetActive(false);
    }
}
